<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>企业员工管理-考核结果</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="static/css/font.css">
    <link rel="stylesheet" href="static/css/xadmin.css">
    <script type="text/javascript" src="static/js/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="static/lib/layui/layui.js"></script>
    <script type="text/javascript" src="static/js/xadmin.js"></script>
    <style type="text/css">
        .laytable-cell-1-eAccount {
            width: 200px;
        }
        .layui-input {
            height: 38px;
            width: 125px;
            line-height: 1.3;
            line-height: 38px \9;
            border-width: 1px;
            border-style: solid;
            background-color: #fff;
            border-radius: 2px
        }


    </style>
</head>

<body class="layui-anim layui-anim-up">

<div class="x-nav">
		<span class="layui-breadcrumb"> <a>首页</a> <a>绩效考核</a> <a> <cite>考核结果</cite></a>
		</span> <a class="layui-btn layui-btn-small"
                   style="line-height: 1.6em; margin-top: 3px; float: right"
                   href="javascript:location.replace(location.href);" title="刷新"> <i
        class="layui-icon" style="line-height: 30px">ဂ</i></a>
</div>
<div class="x-body" id="container">
    <div class="layui-row">
        <div class="demoTable layui-col-md10 layui-form">

            工号：
            <div class="layui-inline">
                <input class="layui-input" name="account" id="eAccount"
                       autocomplete="off">
            </div>
            &nbsp&nbsp 姓名：
            <div class="layui-inline">
                <input class="layui-input" name="name" id="eName"
                       autocomplete="off">
            </div>
            &nbsp&nbsp 部门：

            <div class="layui-input-inline" style="width: 125px;">
                <select name="dep" id="dId" lay-filter="">
                    <option value=""></option>
                </select>
            </div>
            &nbsp&nbsp 上级部门：

            <div class="layui-input-inline" style="width: 125px;">
                <select name="dep" id="dgId" lay-filter="">
                    <option value=""></option>
                </select>
            </div>
            <!--</div>-->
            &nbsp&nbsp
            <button class="layui-btn" data-type="reload">搜索</button>

            &nbsp&nbsp
            <button id="getScoreBtn" class="layui-btn" data-type="reload">生成分数</button>

            &nbsp&nbsp
            <button id="downLoadExcel" class="layui-btn" data-type="reload">导出考核结果</button>

        </div>


    </div>
    <!--demoTable-->
</div>


<div style="text-align: center">
    <table class="layui-table"
           lay-data="{height: 'full-150', cellMinWidth:50, url:'employeeScore/pageTotalScore.do', page:true, id:'idTest'}"
           lay-filter="demo">
        <thead>
        <tr>
            <th
                    lay-data="{field:'tEaccount', width:150, align: 'center'}">
                工号
            </th>
            <th
                    lay-data="{field:'tEname', width:150, align: 'center'}">
                姓名
            </th>

            <th
                    lay-data="{field:'prepareType', width:150, align: 'center'}">
                员工编制
            </th>

            <th
                    lay-data="{field:'tDname', minWidth:250, align: 'center'}">
                部门
            </th>
            <th
                    lay-data="{field:'tDgname', minWidth:250, align: 'center'}">
                上级部门
            </th>
            <th
                    lay-data="{field:'tScoresum', width:100,align: 'center'}">
                总分
            </th>
            <th
                    lay-data="{field:'tXscore', width:100,align: 'center'}">
                周记实分数
            </th>
            <th
                    lay-data="{field:'tGscore', width:100,align: 'center'}">
                满意度分数
            </th>
            <th
                    lay-data="{field:'tQscore', width:120,align: 'center'}">
                工作业绩分数
            </th>
            <th
                    lay-data="{field:'tFscore', width:100,align: 'center'}">
                加分项
            </th>
            <th
                    lay-data="{field:'tHscore', width:100,align: 'center'}">
                考勤分数
            </th>
            <th
                    lay-data="{field:'democraticScore', width:120,align: 'center'}">
                民主评议分数
            </th>
        </tr>
        </thead>
    </table>
</div>

</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>

    window.onload = function () {
        //加载部门下拉搜索框
        var dId = $("#dId");
        let dgId = $("#dgId");
        $.ajax({
            url: 'department/findSelective.do?page=1&limit=999', //分页限制为999条，就是全部
            dataType: 'json',
            type: 'post',
            success: function (result) {
                // console.log(result.data);
                $.each(result.data, function (index, item) {
                    // console.log(index + "&" + item.dId);
                    dId.append("<option value=" + item.dId + ">" + item.dName + "</option>");// 下拉菜单里添加元素
                })
                layui.form.render('select');  //渲染select

            }
        });

        $.ajax({
            url: 'department/superiorDepartments',
            dataType: 'json',
            type: 'post',
            success: function (result) {
                $.each(result, function (index, item) {
                    dgId.append("<option value=" + item.dId + ">" + item.dName + "</option>");// 下拉菜单里添加元素
                })
                layui.form.render('select');  //渲染select
            }
        })

    }

    // 刷新(主要用于批量删除，不能直接在里面刷新，那样会使操作失败，要跳出来执行)
    function myReload() {
        location.replace(location.href);
    }

    $('#getScoreBtn').click(function () {
        // 生成分数
        $.ajax({
            url: 'employeeScore/generateScore.do',
            dataType: 'json',
            type: 'get',
            success: function (result) {
                if (result.code == 100) {
                    layer.msg('生成成功！', {icon: 1, time: 1000});

                } else {
                    layer.msg('生成失败!', {icon: 5, time: 1000});
                }
                //刷新一下
                myReload();
            }
        });
    })

    $('#downLoadExcel').click(function () {
        window.open('employeeScore/getScoreExcel.do', '_blank');
    })

    layui.use(['form', 'layedit', 'laydate', 'table'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , table = layui.table;

        var $ = layui.$, active = {

            reload: function () {
                var eAccount = $('#eAccount');
                var eName = $('#eName');
                var dId = $('#dId');
                let dgId = $('#dgId');


                table.reload('idTest', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        e_account: eAccount.val(),
                        e_name: eName.val(),
                        d_id: dId.val(),
                        d_gsid: dgId.val()
                    }
                });
            },
            getCheckLength: function () { //获取选中数目
                var checkStatus = table.checkStatus('idTest')
                    , data = checkStatus.data;
                if (data.length <= 0) {
                    layer.msg("请至少选择一条数据进行操作")
                    return;
                }
                var ids = [];
                $.each(data, function (index, item) {
                    ids.push(item.employee.eId);
                });

                layer.confirm('确定要删除吗', function (index) {

                    $.ajax({
                        type: 'post',
                        url: 'employee/deleteByQuery.do',
                        data: {"arr": ids},
                        traditional: true,
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == 100) {
                                layer.msg('已删除!', {icon: 1, time: 4000});

                            } else {
                                layer.msg('删除失败!', {icon: 5, time: 1000});
                            }
                        },
                        error: function (data) {
                            // alert("error" + data);
                            layer.alert("网路错误", {icon: 5});
                        }
                    });
                    layer.close(index);
                    relo();

                });
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        function relo() {
            var eAccount = $('#eAccount');
            var eName = $('#eName');
            var dId = $('#dId');
            let dgId = $('#dgId');

            // 执行重载
            table.reload('idTest', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    e_account: eAccount.val(),
                    e_name: eName.val(),
                    d_id: dId.val(),
                    d_gsid: dgId.val()
                }
            });
        }
    });

</script>

</body>

</html>
